<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require_once(dirname(__FILE__) . "/../dbcom/UsertypeCom.php");
$usertypecom = new UsertypeCom();

$cont = $_REQUEST['cont'];

switch ($cont){
    case 1:
        $name = $_REQUEST['name'];
        if(empty($name)){
            echo json_encode(array("code" => 100, "msg" => "empty name"));
            break;
        }
        $res = $usertypecom->addUsertype($name);
        if($res){
            echo json_encode(array("code" => 0, "msg" => "success"));
        }else{
            echo json_encode(array("code" => 400, "msg" => "insert error"));
        }
        break;
    case 2:
        $usertypeid = $_REQUEST['usertypeid'];
        if(empty($usertypeid)){
            echo json_encode(array("code" => 100, "msg" => "empty usertypeid"));
            break;
        }
        $res = $usertypecom->deleteUsertype($usertypeid);
        if($res){
            echo json_encode(array("code" => 0, "msg" => "success","data"=>$usertypeid));
        }else{
            echo json_encode(array("code" => 400, "msg" => "delete error"));
        }
        break;
    default :
        echo json_encode(array("code" => 500, "msg" => "undefined error"));
        break;
}
exit();
